package com.syl.starter.itools.framework.utils.config;

import com.syl.starter.itools.common.utils.StringUtils;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.poi.ss.usermodel.HorizontalAlignment;

/**
 * excel输出配置
 *
 * @author syl
 * @create 2020-05-21 21:09
 **/
@Data
public class ExcelOutputConfig {
    /**
     * 目标sheet下标
     */
    private int sheetIndex;
    /**
     * sheet名称
     */
    private String sheetName = "sheet1";
    /**
     * 开始的行数
     */
    private int startRow;
    /**
     * 开始的列
     */
    private int startColumn;
    /**
     * 表格标题
     */
    private String title;

    private ExcelOutputConfig() {}

    /**
     * 构造输出时的excel配置 默认从第0 sheet，第0行，第0列开始
     * @param title 表格标题
     */
    public ExcelOutputConfig(String title) {
        this(0, title);
    }

    /**
     * 构造输出时的excel配置 默认从sheet中的第0行，第0列开始
     * @param sheetIndex 目标sheet下标
     * @param title 表格标题
     */
    public ExcelOutputConfig(int sheetIndex, String title){
        this(sheetIndex, 0, 0, title);
    }

    /**
     * 构造输出时的excel配置 默认从第0 sheet开始
     * @param startRow 开始的行数
     * @param startColumn 开始的列
     * @param title 表格标题
     */
    public ExcelOutputConfig(int startRow, int startColumn, String title) {
        this(0, startRow, startColumn, title);
    }

    /**
     * 构造输出时的excel 配置
     * @param sheetIndex 目标sheet下标
     * @param startRow 开始的行数
     * @param startColumn 开始的列
     * @param title 表格标题
     */
    public ExcelOutputConfig(int sheetIndex, int startRow, int startColumn, String title) {
        this.sheetIndex = sheetIndex;
        this.startRow = startRow;
        this.startColumn = startColumn;
        this.title = title;
        if (StringUtils.isEmpty(title)) this.setExcelTitle(null);
        else this.getExcelTitle().setTitle(title);
    }

    /**
     * excel 标题配置
     */
    private ExcelTitle excelTitle = new ExcelTitle();
    /**
     * 表格标题配置
     */
    private ExcelHead excelHead = new ExcelHead();
    /**
     * 表格的内容配置
     */
    private ExcelBody excelBody = new ExcelBody();

    @Setter
    @Getter
    @ToString
    @Accessors(chain = true)
    public static class ExcelTitle extends ExcelBaseConfig {
        /**
         * 单元格标题
         */
        private String title;
        /**
         * 合并行数
         */
        private int row = 3;

        @Override
        public HorizontalAlignment getHorizontalAlignment() {
            return HorizontalAlignment.CENTER;
        }

    }

    @Setter
    @Getter
    @ToString
    @Accessors(chain = true)
    public static class ExcelHead extends ExcelBaseConfig{

        @Override
        public HorizontalAlignment getHorizontalAlignment() {
            return HorizontalAlignment.CENTER;
        }

    }

    @Setter
    @Getter
    @ToString
    @Accessors(chain = true)
    public static class ExcelBody extends ExcelBaseConfig{

        @Override
        public boolean isBold() {
            return false;
        }

    }

}
